﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Security.Cryptography;
using System.Text.RegularExpressions;

namespace IT_Pro.Class
{
    class S_TaiKhoan
    {
        public static DataTable ThongtinTaiKhoan(string _matk)
        {
            string strSQL = "select * from TaiKhoan where TaiKhoan='" + _matk + "'";
            return DataServices.ExecQuery(strSQL);
        }

        public static bool DoiMatKhau(string _tk, string _mk)
        {
            string strSQL = "update TaiKhoan set MatKhau='" + _mk + "' where TaiKhoan='"+_tk+"'";
            DataServices.ExecNonQuery(strSQL);
            return true;

        }

        public static string md5(string originalPassword)
        {
            //Declarations
            Byte[] originalBytes;
            Byte[] encodedBytes;
            MD5 md5;

            //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
            md5 = new MD5CryptoServiceProvider();
            originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
            encodedBytes = md5.ComputeHash(originalBytes);

            //Convert encoded bytes back to a 'readable' string
            //  return BitConverter.ToString(encodedBytes);
            return Regex.Replace(BitConverter.ToString(encodedBytes), "-", "");
        }
    }
}
